/**
 * @Description: 请求认证处理
 * @Author: zhen
 * @Date: 2023-10-18
 */
import { DEFAULT_AUTHORIZATION_TOKEN_EXPIRATION, StorageKeys } from '@/constants';
import Cookies from 'js-cookie';

let tokenExpiration = DEFAULT_AUTHORIZATION_TOKEN_EXPIRATION;

// 设置到期时间
export function setTokenExpiration(expires: number) {
  tokenExpiration = expires;
}

// 获取认证token
export function getToken() {
  return Cookies.get(StorageKeys.AuthorizationToken);
}

// 设置认证token
export function setToken(token: string) {
  Cookies.set(StorageKeys.AuthorizationToken, token, {
    expires: new Date(new Date().getTime() + tokenExpiration)
  });
}

// 移除认证token
export function removeToken() {
  Cookies.remove(StorageKeys.AuthorizationToken);
}
